package com.autoTools.router;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

import com.autoTools.util.LogUtil;

public class Router {
	private final static String TAG = "Router";
	
	public static Object run(String command,Object params){
		LogUtil.sysLog(TAG, "command="+command);
		if(command != null){
			String[] splitStr = command.split("\\.");
			
			String commandMethod = splitStr[splitStr.length-1];
			int index = command.indexOf(commandMethod)-1;
			String commandClass = command.substring(0,index);
			LogUtil.sysLog(TAG, "commandClass="+commandClass);
			LogUtil.sysLog(TAG, "commandMethod="+commandMethod);
			Class<?> demo = null;
			Object obj=null;
			try {
				if(commandClass != null && commandMethod != null)
				demo = Class.forName(commandClass);
				if(demo != null){
					obj = demo.newInstance();
					Method method = obj.getClass().getMethod(commandMethod,Object.class);
					return method.invoke(obj,params);
				}
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (SecurityException e) {
				e.printStackTrace();
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}
}
